home *** CD-ROM | disk | FTP | other *** search
/ Aminet 20 / Aminet 20 (1997)(GTI - Schatztruhe)[!][Aug 1997].iso / Aminet / comm / www / HTP.lha / HTP / source / image.c < prev    next >
C/C++ Source or Header  |  1997-06-21  |  2KB  |  93 lines

  1. /*
  2. //
  3. // image.c
  4. //
  5. // Image file functions
  6. //
  7. // Copyright (c) 1995-96 Jim Nelson.  Permission to distribute
  8. // granted by the author.  No warranties are made on the fitness of this
  9. // source code.
  10. // Amiga version - 1997 - Geert Bevin
  11. //
  12. */
  13.  
  14. #include "htp.h"
  15.  
  16. #define IMAGE_TYPE_UNKNOWN              (0)
  17. #define IMAGE_TYPE_GIF                  (1)
  18. #define IMAGE_TYPE_JFIF                 (2)
  19.  
  20. BOOL OpenImageFile(const char *filename, IMAGEFILE *imageFile)
  21. {
  22.     assert(filename != NULL);
  23.     assert(imageFile != NULL);
  24.  
  25.     /* open the file to make sure its reachable */
  26.     if((imageFile->file = fopen(filename, "rb")) == NULL)
  27.     {
  28.         DEBUG_PRINT(("could not open image file %s", filename));
  29.         return FALSE;
  30.     }
  31.  
  32.     /* build the rest of the image file structure */
  33.     if((imageFile->name = DuplicateString(filename)) == NULL)
  34.     {
  35.         DEBUG_PRINT(("could not duplicate filename string"));
  36.         return FALSE;
  37.     }
  38.  
  39.     /* by default, unknown image type */
  40.     imageFile->imageType = IMAGE_TYPE_UNKNOWN;
  41.  
  42.     /* is this a GIF file? */
  43.     if(GifFormatFound(imageFile->file) == TRUE)
  44.     {
  45.         imageFile->imageType = IMAGE_TYPE_GIF;
  46.         return TRUE;
  47.     }
  48.  
  49.     /* is this a JFIF file? */
  50.     if(JpegFormatFound(imageFile->file) == TRUE)
  51.     {
  52.         imageFile->imageType = IMAGE_TYPE_JFIF;
  53.         return TRUE;
  54.     }
  55.  
  56.     /* return TRUE anyways, because the image file is open (although unsure of */
  57.     /* its format or content) */
  58.     return TRUE;
  59. }   
  60.  
  61. void CloseImageFile(IMAGEFILE *imageFile)
  62. {
  63.     assert(imageFile != NULL);
  64.     assert(imageFile->name != NULL);
  65.     assert(imageFile->file != NULL);
  66.  
  67.     FreeMemory(imageFile->name);
  68.     fclose(imageFile->file);
  69.  
  70.     imageFile->name = NULL;
  71.     imageFile->file = NULL;
  72. }   
  73.  
  74. BOOL GetImageDimensions(IMAGEFILE *imageFile, WORD *width, WORD *height)
  75. {
  76.     assert(imageFile != NULL);
  77.     assert(width != NULL);
  78.     assert(height != NULL);
  79.  
  80.     if(imageFile->imageType == IMAGE_TYPE_GIF)
  81.     {
  82.         return GifReadDimensions(imageFile->file, height, width);
  83.     }
  84.     else if(imageFile->imageType == IMAGE_TYPE_JFIF)
  85.     {
  86.         return JpegReadDimensions(imageFile->file, height, width);
  87.     }
  88.  
  89.     /* unknown file type */
  90.     return FALSE;
  91. }   
  92.  
  93.